<template>
  <div class="page-common-layout single-project-container">
    <div class="single-header">
      项目信息管理
      <a-button icon="edit" v-action:xmxxgl_single_edit @click="handleEditor()">
        编辑
      </a-button>
    </div>
    <div class="single-main">
      <div class="introduce-container">
        <div class="base-info">
          <div class="data-item flex-2">
            <div class="label">项目名称：</div>
            <div class="value">
              {{ form.proName }}
            </div>
          </div>
          <div class="data-item">
            <div class="label">项目简称：</div>
            <div class="value">{{ form.proAbbreviation }}</div>
          </div>
          <div class="data-item">
            <div class="label">项目编号：</div>
            <div class="value">{{ form.proCode }}</div>
          </div>
        </div>
        <div class="base-info">
          <div class="data-item">
            <div class="label">项目类型：</div>
            <div class="value">{{ form.engTypeDesc }}</div>
          </div>
          <div class="data-item">
            <div class="label">项目状态：</div>
            <div class="value">
              {{ form.proStatusDesc }}
            </div>
          </div>
          <div class="data-item">
            <div class="label">项目等级：</div>
            <div class="value">{{ form.proLevelDesc }}</div>
          </div>
          <div class="data-item">
            <div class="label">项目规模：</div>
            <div class="value">{{ form.constructionScale }}</div>
          </div>
        </div>
        <div class="base-info">
          <div class="data-item">
            <div class="label">计划开工时间：</div>
            <div class="value">{{ form.startDate }}</div>
          </div>
          <div class="data-item">
            <div class="label">计划竣工时间：</div>
            <div class="value">{{ form.endDate }}</div>
          </div>
          <div class="data-item">
            <div class="label">实际开工时间：</div>
            <div class="value">{{ form.realityStartDate }}</div>
          </div>
          <div class="data-item">
            <div class="label">实际竣工时间：</div>
            <div class="value">{{ form.realityEndDate }}</div>
          </div>
        </div>
        <div class="base-info">
          <div class="data-item">
            <div class="label">总投资额：</div>
            <div class="value">
              {{ Number(form.roadMoney || 0).toLocaleString() }}万元
            </div>
          </div>
          <div class="data-item">
            <div class="label">项目经理：</div>
            <div class="value">{{ form.contacts }}</div>
          </div>
          <div class="data-item">
            <div class="label">联系方式：</div>
            <div class="value">{{ form.contactsPhone }}</div>
          </div>
          <div class="data-item"></div>
        </div>
        <div class="base-info">
          <div class="data-item">
            <div class="label">省市县：</div>
            <div class="value">
              {{ form.workArea ? form.workArea.replace(/@/g, ">") : "" }}
            </div>
          </div>
          <div class="data-item flex-2">
            <div class="label">项目地址：</div>
            <div class="value">{{ form.address }}</div>
          </div>
          <div class="data-item"></div>
        </div>
        <div class="remark">
          <div class="data-item">
            <div class="label">项目简介：</div>
            <div class="value">
              {{ form.introduction }}
            </div>
          </div>
        </div>
        <div class="base-info">
          <div class="data-item">
            <div class="label">项目封面：</div>
            <div class="file">
              <div
                class="image"
                v-for="(item, index) in coverFiles"
                :key="index"
              >
                <ViewerImg :toolbar="false">
                  <img :src="item.url" alt="" />
                </ViewerImg>
              </div>
            </div>
          </div>
          <div class="data-item">
            <div class="label">效果图：</div>
            <div class="file">
              <div
                class="image"
                v-for="(item, index) in effectFiles"
                :key="index"
              >
                <ViewerImg :toolbar="false">
                  <img :src="item.url" alt="" />
                </ViewerImg>
              </div>
            </div>
          </div>
        </div>
        <div class="base-info">
          <div class="data-item">
            <div class="label">全景图：</div>
            <div class="file">
              <div
                class="image"
                v-for="(item, index) in panoramaFiles"
                :key="index"
              >
                <ViewerImg :toolbar="false">
                  <img :src="item.url" alt="" />
                </ViewerImg>
              </div>
            </div>
          </div>
          <div class="data-item">
            <div class="label">宣传视频：</div>
            <div class="file">
              <div
                class="image"
                v-for="(item, index) in promotionalFiles"
                :key="index"
              >
                <video :src="item.url" loop muted="muted" id="video"></video>
                <!-- 暂停 -->
                <div
                  class="play-btn pause"
                  @click="playVideo(0)"
                  v-if="videoStatus == 1"
                ></div>
                <!-- 播放 -->
                <div class="play-btn" @click="playVideo(1)" v-else></div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="table-container">
        <div class="title">参建单位信息</div>
        <div class="body">
          <!-- height="360" -->
          <vxe-table
            ref="xTable"
            align="left"
            show-overflow
            show-header-overflow
            border="default"
            :data="tableData"
            :column-config="{ resizable: true }"
            size="small"
            :loading="loading"
          >
            <vxe-column
              type="seq"
              width="80"
              title="序号"
              align="center"
            ></vxe-column>
            <vxe-column field="orgName" title="单位名称"> </vxe-column>
            <vxe-column field="orgTypeDesc" title="单位类型"> </vxe-column>
            <vxe-column field="orgPerson" title="联系人"> </vxe-column>
            <vxe-column field="orgTelephone" title="联系方式"> </vxe-column>
          </vxe-table>
        </div>
      </div>
    </div>
    <!-- 编辑 -->
    <editorPage
      :key="editorPage.key"
      :visible.sync="editorPage.visible"
      :parameter="editorPage.source"
    ></editorPage>
  </div>
</template>

<script>
import { axios } from "@/utils/request";
import { _getUUID } from "@/utils/util.js";
import ViewerImg from "@/components/TopVUI/custom/ViewerImg";
//编辑
import editorPage from "./editorPage";
export default {
  components: {
    editorPage,
    ViewerImg,
  },
  data() {
    return {
      form: {},
      tableData: [],
      loading: false,
      //封面图
      coverFiles: [],
      //效果图
      effectFiles: [],
      //全景图
      panoramaFiles: [],
      //宣传视频
      promotionalFiles: [],
      //编辑
      editorPage: {
        visible: false,
        key: _getUUID(),
        source: {},
      },
      videoStatus: 0,
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    //编辑
    handleEditor() {
      this.editorPage.key = _getUUID();
      this.editorPage.source = this.form;
      this.editorPage.visible = true;
    },
    getData() {
      axios
        .post(
          `/mdata/sysProject/queryProByProCode`,
          {},
          {
            headers: {
              "Content-Type": "application/json",
            },
          }
        )
        .then((res) => {
          this.form = res;
          this.tableData = res?.unitList ?? [];
          //封面图
          this.coverFiles = JSON.parse(res?.proImage ?? "[]");
          //效果图
          this.effectFiles = JSON.parse(res?.effectImages ?? "[]");
          //全景图
          this.panoramaFiles = JSON.parse(res?.panoramaImages ?? "[]");
          //宣传视频
          this.promotionalFiles = JSON.parse(res?.promotionalVideo ?? "[]");
        })
        .catch((_) => {
          this.form = {};
          this.coverFiles = [];
          this.effectFiles = [];
          this.panoramaFiles = [];
          this.promotionalFiles = [];
          this.tableData = [];
        })
        .finally(() => {});
    },
    //视频播放
    playVideo(type = 0) {
      let videoDom = document.getElementById("video");
      this.videoStatus = type;
      if (type == 1) {
        //全屏
        if (videoDom.requestFullscreen) {
          videoDom.requestFullscreen();
        } else if (videoDom.mozRequestFullScreen) {
          videoDom.mozRequestFullScreen();
        } else if (videoDom.webkitRequestFullscreen) {
          videoDom.webkitRequestFullscreen();
        }
        //播放
        videoDom.play();
      } else {
        //暂停
        videoDom.pause();
      }
    },
  },
};
</script>

<style lang="less" scoped>
.single-project-container {
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border-radius: 6px;
  overflow: hidden;
  .single-header {
    height: 64px;
    border-bottom: 1px solid #d9d9d9;
    padding: 0 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 20px;
    color: #333333;
    flex-shrink: 0;
  }
  .single-main {
    flex: 1;
    padding: 16px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    overflow: auto;
    .introduce-container {
      background: rgba(250, 250, 250, 0.5);
      border-radius: 0px 0px 0px 0px;
      border: 1px solid #ededed;
      margin-bottom: 16px;
      padding: 20px;
      box-sizing: border-box;
      display: flex;
      flex-direction: column;
      justify-content: center;
      .data-item {
        display: flex;
        font-weight: 400;
        font-size: 14px;
        flex: 1;
        &.flex-2 {
          flex: 2;
        }
        .label {
          width: 100px;
          color: #8a9295;
          flex-shrink: 0;
          text-align: right;
        }
        .value {
          color: #333333;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          overflow: hidden;
          text-overflow: ellipsis;
        }
        .file {
          flex: 1;
          display: flex;
          flex-wrap: wrap;

          .image {
            width: 110px;
            height: 110px;
            border-radius: 6px;
            border: 1px solid #d9d9d9;
            margin-right: 8px;
            margin-bottom: 8px;
            position: relative;
            div {
              height: 100%;
              width: 100%;
            }
            img {
              border-radius: 6px;
              height: 100%;
              width: 100%;
              object-fit: cover;
            }
            video {
              object-fit: fill;
              border-radius: 6px;
              height: 100%;
              width: 100%;
            }
            .play-btn {
              position: absolute;
              width: 24px;
              height: 24px;
              top: 50%;
              left: 50%;
              transform: translate(-50%, -50%);
              cursor: pointer;
              background: url("~@/assets/img/home/playBtn.png");
              background-size: 100% 100%;
              &.pause {
                background: url("~@/assets/img/home/pauseBtn.png");
                background-size: 100% 100%;
                opacity: 0;
                transition: 0.3s;
              }
            }
            &:hover {
              .pause {
                opacity: 1;
              }
            }
          }
        }

        &:last-of-type {
          margin-right: 0;
        }
      }
      .base-info {
        display: flex;
        flex-wrap: nowrap;
        margin-bottom: 16px;
        .data-item {
          .value {
            -webkit-line-clamp: 1;
          }
        }
      }
      .remark {
        display: flex;
        flex-wrap: nowrap;
        justify-content: space-between;
        margin-bottom: 16px;
        .data-item {
          .value {
            -webkit-line-clamp: 2;
          }
        }
      }
    }
    .table-container {
      background: rgba(250, 250, 250, 0.5);
      border-radius: 0px 0px 0px 0px;
      border: 1px solid #ededed;
      padding: 20px;
      box-sizing: border-box;
      display: flex;
      flex-direction: column;
      .title {
        font-size: 18px;
        color: #333333;
        margin-bottom: 20px;
      }
      .body {
        flex: 1;
        background: #ffffff;
      }
    }
  }
}
</style>
